<?php
/**
 * Article.php
* 跨境电商商城系统
 * =============================================
 * Copy right 2016-2026 大连熠泽科技网络有限公司
 * ---------------------------------------------
 * 官方网址: http://www.yizehuitong.com
 * =============================================
 * @author : yizehuitong
 * @date : 2019.10
 * @version : v2.0
 */

namespace app\api\controller;

use data\service\Article as ArticleService;

class Article extends BaseApi
{
	
	/**
	 * 文章列表
	 */
	public function articleList()
	{
		$article = new ArticleService();
		$page_index = isset($this->params['page_index']) ? $this->params['page_index'] : 1;
		$page_size = isset($this->params['page_size']) ? $this->params['page_size'] : PAGESIZE;
		$condition = isset($this->params['condition']) ? $this->params['condition'] : "";
        $order = isset($this->params['order']) ? $this->params['order'] : "public_time desc";
        if (! empty($condition) && is_string($condition) && json_decode($condition)) {
            $condition = json_decode($condition, true);
        }
        $result = $article->getArticleList($page_index, $page_size, $condition, $order);
		return $this->outMessage("", $result);
	}
	
	/**
	 * 文章详情
	 */
	public function articleInfo()
	{
		$article = new ArticleService();
		$article_id = isset($this->params['article_id']) ? $this->params['article_id'] : 0;
		$info = $article->getArticleDetail($article_id);
		if (!empty($info)) {
			$info["content"] = htmlspecialchars_decode(html_entity_decode($info["content"], ENT_COMPAT, "UTF-8"), ENT_COMPAT);
		}
		return $this->outMessage("文章详情", $info);
	}
	
	/**
	 * 获取文章分类
	 */
	public function articleClassList()
	{
		$article = new ArticleService();
		$page_index = isset($this->params['page_index']) ? $this->params['page_index'] : 1;
		$page_size = isset($this->params['page_size']) ? $this->params['page_size'] : 0;
		$condition = isset($this->params['condition']) ? $this->params['condition'] : "";
        $order = isset($this->params['order']) ? $this->params['order'] : "sort desc";
        if (! empty($condition) && is_string($condition) && json_decode($condition)) {
            $condition = json_decode($condition, true);
        }
        $list = $article->getArticleClass($page_index, $page_size, $condition, $order);
		return $this->outMessage("获取文章分类", $list);
	}
	
	/**
	 * 获取专题详情
	 */
	public function topicInfo()
	{
		$article = new ArticleService();
		$topic_id = isset($this->params['topic_id']) ? $this->params['topic_id'] : "";
		$res = $article->getTopicDetail($topic_id);
		return $this->outMessage("获取专题详情", $res);
	}
	
	/**
	 * 最*的一条数据
	 */
	public function articleFirst()
	{
		$order = isset($this->params['order']) ? $this->params['order'] : '';
		$condition = isset($this->params['condition']) ? $this->params['condition'] : "";
		if (! empty($condition) && is_string($condition) && json_decode($condition)) {
            $condition = json_decode($condition, true);
        }
		$article = new ArticleService();
		$data = $article->getArticleFirst($condition, $order);
		return $this->outMessage("获取文章", $data);
	}
	
	/**
	 * 获取文章分类信息
	 */
	public function articleClassInfo()
	{
		$article = new ArticleService();
		$class_id = isset($this->params['class_id']) ? $this->params['class_id'] : "";
		$field = isset($this->params['field']) ? $this->params['field'] : "*";
		$data = $article->getArticleClassDetail($class_id,$field);
		return $this->outMessage('获取文章分类信息', $data);
	}
}